<!-- 订单购买页 -->
<template>
  <section>
    <van-list
      v-model="loading"
      :finished="finished"
      @load="onLoad"
      loading-text="正在加载..."
    >
    <template v-for="item in list">
      <van-card
        tag="砍价商品"
        :price="item.kjPrice"
        desc=""
        :title="item.title"
        :thumb="item.picName"
        :origin-price="item.nowPrice"
      >
        <div slot="footer">
          <van-button size="mini" type="danger" @click="goDetail(item.id);">去砍价</van-button>
        </div>
      </van-card>
    </template>
    </van-list>

    <div class="weui-loadmore weui-loadmore_line" v-if="finished && list.length!=0 && page>1">
      <span class="weui-loadmore__tips">{{loadMsg}}</span>
    </div>

    <van-tabbar v-model="active">
      <van-tabbar-item name="home" @click="goUrl('/index');" icon="wap-home">首页</van-tabbar-item>
      <van-tabbar-item name="kan" @click="goUrl('/kan');" icon="fire-o">砍价商品</van-tabbar-item>
      <van-tabbar-item name="cart" @click="goUrl('/cart');" icon="shopping-cart-o">购物车</van-tabbar-item>
      <van-tabbar-item name="order" @click="goUrl('/user');"  icon="orders-o">我的订单</van-tabbar-item>
    </van-tabbar>
  </section>
</template>
<script>
  import goodsService from '../../api/goodsService';
  export default {
    name:'index',
    data() {
      return {
        active:'home',
        datalist: [],
        list: [],
        loading: false,
        finished: false,
        loadMsg: '暂无数据',
        totalPage: '',
        page: 1
      }
    },
    methods: {
      goUrl(url) {
        this.$nocacheRouter(url);
      },
      goDetail(id) {
        this.$nocacheRouter('/kanDetail?id='+id);
      },
      _resetList() {
        this.finished = true;
        this.$nextTick(function(){
          this.page = 1;
          this.loading = false;
          this.finished = false;
          this.datalist = [];
          this.list = [];
        });

      },

      onLoad() {
        var that = this;
        if(this.timer) {
          clearTimeout(this.timer);
        }
        this.timer = setTimeout(() => {
          that.getList();
      }, CONSTANT.LIST_TIMEOUT);
      },
      getList() {
        goodsService.goodsListByGrade({currPage:this.page,pageSize:10,isKj:1}).then((rsp)=>{
          if(rsp.result) {
          this.loading = false;
          this.list = this.list.concat(rsp.obj.goodsList);
          var totalPage = rsp.obj.totalPage;
          if ((this.page + 1) > totalPage) {
            this.finished = true;
            this.loadMsg = '我是有底线的';
          }else {
            this.page = this.page + 1;
          }
        }else {
          this.$toast(rsp.errorMsg);
        }
      }).catch((error)=>{
          this.$toast('goodsListByGrade接口异常'+error);
      });
      },
    },

    mounted(){
    }
  };
</script>
<style scoped>

</style>

<style>
  .van-tabbar-item--active{
    color: #f44;
  }
</style>
